package cn.iocoder.yudao.module.nmkj.controller.admin.teamintroduce;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.nmkj.controller.admin.teamintroduce.vo.*;
import cn.iocoder.yudao.module.nmkj.dal.dataobject.teamintroduce.TeamIntroduceDO;
import cn.iocoder.yudao.module.nmkj.service.teamintroduce.TeamIntroduceService;

@Tag(name = "管理后台 - 团队介绍")
@RestController
@RequestMapping("/nmkj/team-introduce")
@Validated
public class TeamIntroduceController {

    @Resource
    private TeamIntroduceService teamIntroduceService;

    @PostMapping("/create")
    @Operation(summary = "创建团队介绍")
    @PreAuthorize("@ss.hasPermission('nmkj:team-introduce:create')")
    public CommonResult<Long> createTeamIntroduce(@Valid @RequestBody TeamIntroduceSaveReqVO createReqVO) {
        return success(teamIntroduceService.createTeamIntroduce(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新团队介绍")
    @PreAuthorize("@ss.hasPermission('nmkj:team-introduce:update')")
    public CommonResult<Boolean> updateTeamIntroduce(@Valid @RequestBody TeamIntroduceSaveReqVO updateReqVO) {
        teamIntroduceService.updateTeamIntroduce(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除团队介绍")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('nmkj:team-introduce:delete')")
    public CommonResult<Boolean> deleteTeamIntroduce(@RequestParam("id") Long id) {
        teamIntroduceService.deleteTeamIntroduce(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得团队介绍")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('nmkj:team-introduce:query')")
    public CommonResult<TeamIntroduceRespVO> getTeamIntroduce(@RequestParam("id") Long id) {
        TeamIntroduceDO teamIntroduce = teamIntroduceService.getTeamIntroduce(id);
        return success(BeanUtils.toBean(teamIntroduce, TeamIntroduceRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得团队介绍分页")
    @PreAuthorize("@ss.hasPermission('nmkj:team-introduce:query')")
    public CommonResult<PageResult<TeamIntroduceRespVO>> getTeamIntroducePage(@Valid TeamIntroducePageReqVO pageReqVO) {
        PageResult<TeamIntroduceDO> pageResult = teamIntroduceService.getTeamIntroducePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, TeamIntroduceRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出团队介绍 Excel")
    @PreAuthorize("@ss.hasPermission('nmkj:team-introduce:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportTeamIntroduceExcel(@Valid TeamIntroducePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<TeamIntroduceDO> list = teamIntroduceService.getTeamIntroducePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "团队介绍.xls", "数据", TeamIntroduceRespVO.class,
                        BeanUtils.toBean(list, TeamIntroduceRespVO.class));
    }

}